Repository navigation
C++: Explain converted constants in comparison alerts - #23202
Open
SkyCipherr wants to merge 1 commit into
Open
SkyCipherr wants to merge 1 commit into
SkyCipherr wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Parenthesized casts bypass integral-conversion detection, causing alerts to lose the -1 explanation; the query needs to handle trailing parentheses and add a regression case.
1 open issue
What changed in this PR
This PR improves cpp/constant-comparison alerts by explaining converted constant values alongside inferred operand bounds, addressing the unclear diagnostics in #11744.
Changes:
- Adds converted-value explanations for constant operands on either side of a comparison.
- Adds regression cases for value-changing and value-preserving conversions.
- Updates query help and adds a release note.
| File | Description |
|---|---|
cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/PointlessComparison.expected |
Records expected alerts for the new regression cases. |
cpp/ql/test/query-tests/Likely Bugs/Arithmetic/PointlessComparison/ConvertedConstants.c |
Tests conversions on both sides and an unchanged constant value. |
cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql |
Adds converted constant values to alert explanations. |
cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.qhelp |
Documents the explanation and corrects the comparison example. |
cpp/ql/src/change-notes/2026-11-23-constant-comparison-conversions.md |
Announces the diagnostic improvement. |
Review effort: Balanced (adaptive)
Comment on lines
+25
to
+26
| operand.getUnconverted().getValue() != | ||
| operand.getFullyConverted().(IntegralConversion).getValue() |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

When a constant operand changes value during integral conversion, include the converted value in the
cpp/constant-comparisonalert. In the reduced libarchive example, the message now explains that the constant on the right evaluates to-1, in addition to reporting the inferred bound on the left.Added regression cases for a converted constant on each side and for a value-preserving conversion. Both tests in the
PointlessComparisonsuite pass. The comparison against the original query on the same fixtures showed the same 56 findings, with wording changes limited to the two new value-changing conversion cases.Fixes #11744.